#pragma once

/*
	File:	DirectInput.h
	Author:	TJ Ashby
	
	Comments:	Listens for input from various devices.
*/

#include <dinput.h>

#pragma comment(lib,"dinput8.lib")
#pragma comment(lib,"dxguid.lib")

#include "DirectX.h"

class DirectInput
{
	// Singleton
	DirectInput(void);
	~DirectInput(void);

	// Direct Input
	IDirectInput8 *pDirectInput;
	IDirectInputDevice8 *pKeyboard;
	IDirectInputDevice8 *pMouse;
	IDirectInputDevice8 *pJoystic1;
	IDirectInputDevice8 *pJoystic2;

	bool inputOK;

	struct MouseState
	{
		int x,y,z;
		BYTE rgbButtons[4];
	};
	MouseState prevState;
	DIMOUSESTATE *mouseState;

	bool mouseClicked;

	BYTE keys[256];
	BYTE prevKeys[256];
	HKL	 keyLayout;

public:
	static DirectInput* getInstance();

	void Initialize(HWND hwnd,HINSTANCE hInst,bool bShowCursor = false);
	void Shutdown();

	bool KeyPressed(unsigned char Key);
	bool KeyDown(unsigned char Key);
	unsigned char getKeyDown();
	bool KeyUp(unsigned char Key);
	bool KeyReleased(unsigned char Key);
	bool AnyKeyDown();

	bool MouseButtonDown(int Button);
	bool MouseButtonUp(int Button);
	bool MouseButtonClicked(int Button);
	bool MouseButtonReleased(int Button);
	Vector2 MouseDelta();
	int MouseScroll();

	void Update();
	void Clear();
	void ClearMouse();
	void ClearKeys();
};

